<?php

//话题墙模型
class Wall_model extends Model {

	function Wall_model() 
	{
		parent::Model();	
		$this->load->database();
		$this->load->model("site_modle", "sm");
		$this->load->model("comment_model");
	} 
	
	//获取话题列表
	function lists($classid = 0, $limit = 2, $offset = 0, $order = "id", $sortby = "desc", $iswall = 1)
	{
		$lists = array();
		$this->db->from("module_forum");
		if($classid > 0) {
			$this->db->where("classid", $classid);
		}
		if($iswall == 1) {
			$this->db->where("iswall", 1);
		}
		$this->db->order_by($order, $sortby);
		$this->db->limit($limit, $offset);
		$query = $this->db->get();
		if($query->num_rows()>0) {
			$lists = $query->result_array();
			foreach($lists as $k => $list){
				$siteid = $list["siteid"];
				$site = $this->sm->get($siteid);
				if(isset($site) && count($site) > 0) {
					$lists[$k]["domain"] = $site["domain"];
					$lists[$k]["sitename"] = $site["name"];
					$lists[$k]["logo"] = $site["logo"];
				} else {
					$lists[$k]["domain"] = "";
					$lists[$k]["sitename"] = "";
					$lists[$k]["logo"] = "";
				}
				
				//用户信息
				$userid = $list["userid"];
				$userinfo = $this->am->get($userid);
				$lists[$k]["userinfo"] = $userinfo;
				//评论总数
				$commentcount = $this->comment_model->count_forum_lists($siteid, $list["id"]);
				$lists[$k]["commentcount"] = $commentcount;
				//内容图片检测
				$haspic = false;
				$pics = get_content_pics($list["description"]);
				if($pics && is_array($pics) && count($pics) > 0) {
					$haspic = true;
				}
				$lists[$k]["haspic"] = $haspic;
			}
		}
		return $lists;
	}
	
	//计算总数
	function count_lists($classid, $iswall = 1)
	{
		$this->db->from("module_forum");
		if($classid > 0) {
			$this->db->where("classid", $classid);
		}
		if($iswall == 1) {
			$this->db->where("iswall", $iswall);
		}
		$query = $this->db->get();
		return $query->num_rows();
	}
	
}

/* End of file */